/* 
 * File:   TreeOfNodes.h
 * Author: jcrada
 *
 * Created on April 5, 2009, 12:16 AM
 */

#ifndef _TREEOFNODES_H
#define	_TREEOFNODES_H

#include "Node.h"
#include "FunctionNode.h"
#include "TerminalNode.h"

#include <QtXml/QDomElement>
#include <QtXml/QDomDocument>

namespace jcrada {

    class TreeOfNodes {
    private:
        Node* _root;
        double _fitness;
    public:
        TreeOfNodes();
        TreeOfNodes(Node* root);
        virtual ~TreeOfNodes();

        virtual void setRoot(Node * root) {
            this->_root = root;
        }

        virtual Node* getRoot() const {
            return this->_root;
        }

        virtual void addFitness(double fitness) {
            this->_fitness += fitness;
        }

        virtual void setFitness(double fitness) {
            this->_fitness = fitness;
        }

        virtual double getFitness() const {
            return this->_fitness;
        }

        virtual int getSize() const {
            return getRoot() ? getRoot()->getTreeSize() : 0;
        }

        virtual int getDepth() const {
            return getRoot() ? getRoot()->getDepth() : 0;
        }

        Node* findNodeUsingBFS(int position) const;
        virtual int findPositionUsingBFS(const Node* node) const;

        virtual TreeOfNodes* clone() const;

        virtual std::vector<FunctionNode*>* getFunctionNodes() const;
        virtual std::vector<TerminalNode*>* getTerminalNodes() const;

        virtual std::string toString() const;

        virtual void toXml(QDomDocument& xml, QDomElement* parent = NULL);
    };
}


#endif	/* _TREEOFNODES_H */

